﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using StuMngWx.Entities;
using DX.CRC.Common.Entities;

namespace StuMngWx.Dals
{
    class Dal4Student : DalBase
    {
        public static List<Student> SearchAllStudents()
        {
            QueryObject qo = CreateQO();

            qo.CmdText = @"SELECT [ListID] as ID
	            ,[Name]
	            ,[Sex] as Sex_Field
	            ,[Address]
            FROM [dbo].[Student]
            where IsActive = 1;";

            return qo.xExecuteList<Student>();
        }

        [Obsolete("【闻祖东 2013-2-4-230158】此方法以及作废，请使用重载的以Student作为参数的方法。")]
        public static void InsertStudent(string name, bool sex, string address)
        {
            QueryObject qo = CreateQO();

            qo.CmdText = @"INSERT INTO [dbo].[Student]
                   ([Name]
                   ,[Sex]
                   ,[Address]
                   ,[IsActive]
                   ,[CreateTime]
                   ,[Remarks])
             VALUES
                   (@Name
                   ,@Sex
                   ,@Address
                   ,1
                   ,GETUTCDATE()
                   ,N'')";

            qo.AddParam("@Name", name);
            qo.AddParam("@Sex", sex);
            qo.AddParam("@Address", address);

            qo.xExecuteNonQuery();
        }

        public static void InsertStudent(Student student)
        {
            QueryObject qo = CreateQO();

            qo.CmdText = @"INSERT INTO [dbo].[Student]
                   ([Name]
                   ,[Sex]
                   ,[Address]
                   ,[IsActive]
                   ,[CreateTime]
                   ,[Remarks])
             VALUES
                   (@Name
                   ,@Sex
                   ,@Address
                   ,1
                   ,GETUTCDATE()
                   ,N'')";

            qo.AddParam("@Name", student.Name);
            qo.AddParam("@Sex", student.Sex);
            qo.AddParam("@Address", student.Address);

            qo.xExecuteNonQuery();
        }
    }
}
